<?php
header('Content-Type: application/json; charset=utf-8');
require_once 'main.class.php';
try {
//    $uid = 6486513;
//    $category= "asdagsg";
//    $size = 10;
//    $gachaTs = null;
//    $pos = null;
    $MASSAGE = parse_ini_file("./resource/MASSAGE.ini", true)["amiya"];
    if (isset($_GET['token'])){
        $param = array(
            'token' => $_GET['token']
        );
    }elseif (isset($_GET['phoneNumber']) && isset($_GET['password'])){
        $param = array(
            'phoneNumber' => $_GET['phoneNumber'],
            'password' => $_GET['password']
        );
    }else{
        throw new HypergryphGachaAPIError($MASSAGE['INIT_PARAMETER_ERROR']);
    }
    if (isset($_GET["channel"])) {
        $param["channel"] = $_GET["channel"];
    }
    $API = new HypergryphGachaAPI($param);
    $allGacha = $API->getFormatGachaData();

    echo(json_encode($allGacha, JSON_UNESCAPED_UNICODE));
} catch (HypergryphGachaAPIError $e) {
    http_response_code(400);
    if (php_sapi_name() == 'cli'){
        echo $e->getLogger();
    }else{
        echo $e->getLoggerByJson();
    }
    exit();
}